package minidb.type;

import static minidb.type.Const.*;

public class IntConstant implements Constant{
	private Integer val;

	public IntConstant(){
		val = INT_NULL;
	}
	
	public IntConstant(int val){
		this.val = val;
	}
	
	public Object toVal(){
		return this.val;
	}

	public boolean equals(Object obj) {
		IntConstant ic = (IntConstant) obj;
		return ic != null && val.equals(ic.val);
	}

	public int compareTo(Constant c) {
		if(IntConstant.class.isInstance(c))
			return val.compareTo((Integer)c.toVal());
		else
			return (new Double(val)).compareTo((Double)c.toVal());
		
	}

	public int hashCode() {
		return val.hashCode();
	}

	public String toString() {
		return val.toString();
	}

	public Boolean isNull() {
		return val==INT_NULL;
	}
}
